package chpt04;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;


class PersonSortable2 {
	private String name;
	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public PersonSortable2(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PersonSortable2 other = (PersonSortable2) obj;
		if (age != other.age)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
}
/*
 class NameComparator implements Comparator<PersonSortable2>{

	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		return o1.getName().compareTo(o2.getName());
	}
	
}
 class AgeComparator implements Comparator<PersonSortable2>{

	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		return o1.getAge()-o2.getAge();
	}
	 
 }
 */
public class PortComparator {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		while (in.hasNext()) {
			ArrayList<PersonSortable2> persons = new ArrayList<PersonSortable2>();
			for (int i = 0; i < n; i++) {
				persons.add(new PersonSortable2(in.next(), in.nextInt()));
			}
			//Collections.sort(persons,new NameComparator());
			/*Collections.sort(persons,new Comparator<PersonSortable2>(){

				@Override
				public int compare(PersonSortable2 o1, PersonSortable2 o2) {
					return o1.getName().compareTo(o2.getName());
				}
				
			});*/
			Comparator<PersonSortable2> nameComparator = (o1,o2)->o1.getName().compareToIgnoreCase(o2.getName());
			Collections.sort(persons,nameComparator);
			System.out.println("NameComparator:sort");
			for (PersonSortable2 p : persons) {
				System.out.println(p);
			}
			//Collections.sort(persons,new AgeComparator());
			/*Collections.sort(persons,new Comparator<PersonSortable2>(){

				@Override
				public int compare(PersonSortable2 o1, PersonSortable2 o2) {
					return o1.getAge()-o2.getAge();
				}
				
			});*/
			Comparator<PersonSortable2> ageComparator = (o1,o2)->o1.getAge()-o2.getAge();
			Collections.sort(persons,ageComparator);
			System.out.println("AgeComparator:sort");
			for (PersonSortable2 p : persons) {
				System.out.println(p);
			}
			//System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
			//System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
		}
		in.close();

	}

}
